package pl.pyjter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="Book")
public class Book {
	private int id;
	private Author author;
	private String title;
	private String ISBN;
	private Publisher publisher;
	
	private static String[] columnsOrder = {"id", "title", "ISBN"};
    public static String[] getColumnsOrder() {
    	return columnsOrder;
    }
	
	@Id
	@GeneratedValue
	@Column(name="id")
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="aid")
	public Author getAuthor() {
		return author;
	}
	
	public void setAuthor(Author author) {
		this.author = author;
	}
	
	@Column(name="title")
	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	@Column(name="ISBN")
	public String getISBN() {
		return ISBN;
	}
	
	public void setISBN(String ISBN) {
		this.ISBN = ISBN;
	}	
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="pid")
	public Publisher getPublisher() {
		return publisher;
	}
	
	public void setPublisher(Publisher publisher) {
		this.publisher = publisher;
	}	
	
	public void display() {
		System.out.println(id + "|" + title + "|" + author.getName() + "|" + author.getSurname() + "|" + ISBN + "|"
				+ publisher.getName());
	}
}
